package com.example.myapplication.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.example.myapplication.R;
import com.example.myapplication.databinding.FragmentTianqi1Binding;
import com.example.tqlibrary.javabean.databean;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */

  //Tianqi1Fragment时界面一，主要时提供未来段时间准点时的天气情况
public class Tianqi1Fragment extends Fragment {
    List<databean.HeWeather6Bean> hourlyBeanList;
    public Tianqi1Fragment(List<databean.HeWeather6Bean> hourlyBeanList) {
       this.hourlyBeanList = hourlyBeanList;
    }
    FragmentTianqi1Binding tianqi1Binding;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        tianqi1Binding =FragmentTianqi1Binding.inflate( inflater );

        //取时间00:00
        tianqi1Binding.text1s.setText(hourlyBeanList.get(0).getHourly().get(0).getTime().substring(10,16)+"");
        tianqi1Binding.text2s.setText(hourlyBeanList.get(0).getHourly().get(1).getTime().substring(10,16)+"");
        tianqi1Binding.text3s.setText(hourlyBeanList.get(0).getHourly().get(2).getTime().substring(10,16)+"");
        tianqi1Binding.text4s.setText(hourlyBeanList.get(0).getHourly().get(3).getTime().substring(10,16)+"");
        tianqi1Binding.text5s.setText(hourlyBeanList.get(0).getHourly().get(4).getTime().substring(10,16)+"");
        tianqi1Binding.text6s.setText(hourlyBeanList.get(0).getHourly().get(5).getTime().substring(10,16)+"");


        tianqi1Binding.text1x.setText(hourlyBeanList.get(0).getHourly().get(0).getTmp()+"°");
        tianqi1Binding.text2x.setText(hourlyBeanList.get(0).getHourly().get(1).getTmp()+"°");
        tianqi1Binding.text3x.setText(hourlyBeanList.get(0).getHourly().get(2).getTmp()+"°");
        tianqi1Binding.text4x.setText(hourlyBeanList.get(0).getHourly().get(3).getTmp()+"°");
        tianqi1Binding.text5x.setText(hourlyBeanList.get(0).getHourly().get(4).getTmp()+"°");
        tianqi1Binding.text6x.setText(hourlyBeanList.get(0).getHourly().get(5).getTmp()+"°");

        View views[] = {this.tianqi1Binding.imageView,this.tianqi1Binding.imageView1,this.tianqi1Binding.imageView2,
                this.tianqi1Binding.imageView3,this.tianqi1Binding.imageView4,this.tianqi1Binding.imageView5};

        for(int i = 0; i < 6;i++){
            switch (hourlyBeanList.get(0).getHourly().get(i).getCond_txt()){

                case "晴":views[i].setBackground(getResources().getDrawable(R.drawable.sun));break;
                case "阴":views[i].setBackground(getResources().getDrawable(R.drawable.yin));break;
                case "多云":views[i].setBackground(getResources().getDrawable(R.drawable.yin));break;
                case "大风":views[i].setBackground(getResources().getDrawable(R.drawable.dafeng));break;
                case "小雨":views[i].setBackground(getResources().getDrawable(R.drawable.xiaoyu));break;
                case "中雨":views[i].setBackground(getResources().getDrawable(R.drawable.zhongyu));break;
                case "大雨":views[i].setBackground(getResources().getDrawable(R.drawable.dayu));break;
                case "雷阵雨":views[i].setBackground(getResources().getDrawable(R.drawable.leizhenyu));break;

                default:views[i].setBackground(getResources().getDrawable(R.drawable.sun));break;
            }
        }

        return tianqi1Binding.getRoot();
    }
}
